﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Api.Common
{
    // Items in the shopping list
    public class SitemapLocation
    {
        /// <summary>
        /// 使用的规则是首页使用always
        /// 很久前的链接或者没什么意义的链接使用yearly或则never
        /// 越往下表示ping
        /// </summary>
        public enum eChangeFrequency
        {
            always,
            hourly,
            daily,
            weekly,
            monthly,
            yearly,
            never
        }

        string url;
        /// <summary>
        /// 具体网址，特殊字符转义
        /// & ->&amp;
        /// ' ->&apos;
        /// > ->&gt;
        /// < ->&lt;
        /// </summary>
        [XmlElement("loc")]
        public string Url
        {
            get { return url; }
            set { url = (value ?? string.Empty).Replace("&", "&amp;").Replace("'", "&apos;").Replace(">", "&gt;").Replace("<", "&lt;"); }
        }
        /// <summary>
        /// 页面内容更新频率
        /// </summary>

        [XmlElement("changefreq")]
        public eChangeFrequency? ChangeFrequency { get; set; }
        public bool ShouldSerializeChangeFrequency() { return ChangeFrequency.HasValue; }

        /// <summary>
        /// 页面最后修改时间
        /// YYYY-MM-DDThh:mmTZD
        /// </summary>
        [XmlElement("lastmod")]
        public DateTime? LastModified { get; set; }
        public bool ShouldSerializeLastModified() { return LastModified.HasValue; }

        /// <summary>
        /// 相对于其他页面的优先权
        /// </summary>
        [XmlElement("priority")]
        public double? Priority { get; set; }
        public bool ShouldSerializePriority() { return Priority.HasValue; }

        [XmlElement("image", Namespace = "http://www.google.com/schemas/sitemap-image/1.1")]
        public List<SitemapImage> Images { get; set; }
        public bool ShouldSerializeImages() { return Images != null && Images.Count > 0; }
    }
}
